import {getTagList} from '@/services'
import { allArticleItem, articleRecommentItem, IArticleItem, ITagItem } from '@/types';
import { Effect, Reducer } from 'umi';

export interface TagModelState {
    tagList:ITagItem[]
}

export interface TagModelType {
  namespace: 'tag';
  state: TagModelState;
  effects: {
   
    getTagList: Effect;
  };
  reducers: {
    save: Reducer<TagModelState>;

  };

}

const TagModel: TagModelType = {
  namespace: 'tag',

  state: {
    tagList:[]
  },
  //副作用
  effects: {
   
    *getTagList({ }, { call, put }) {
      const result = yield call(getTagList)
       
      if (result.data) {
        yield put({
          type: 'save',
          payload: {
            tagList: result.data,
          }
        })
      } 
    }
  },
  //同步修改state的操作
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },

  },

};

export default TagModel;


